package com.pubinfo.passbook.common.handler.excel;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.pubinfo.passbook.common.enums.ContractImportStatusEnum;

/**
 * String and string converter
 *
 * @author Jiaju Zhuang
 */
public class CustomImportStatusConverter implements Converter<Integer> {
  @Override
  public Class<?> supportJavaTypeKey() {
    return Integer.class;
  }
  
  @Override
  public CellDataTypeEnum supportExcelTypeKey() {
    return CellDataTypeEnum.NUMBER;
  }
  
  /**
   * 这里读的时候会调用
   *
   * @return
   */
  @Override
  public Integer convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty,
                                   GlobalConfiguration globalConfiguration) {
    String status = cellData.getStringValue();
    return ContractImportStatusEnum.getStatusCodeByName(status);
  }
  
  /**
   * 这里是写的时候会调用 不用管
   *
   * @return
   */
  @Override
  public WriteCellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
    
    //     return new WriteCellData<>(Boolean.FALSE);
    return new WriteCellData<>(ContractImportStatusEnum.getEnum(value).getDesc());
  }
  
}
